package com.dj.product.k2faas.jpa.sqlgenerator;

/**
 * Created by 丁建 on 2025/9/23 10:10
 *
 * @author 丁建
 */
public class PostgresSqlGenerator extends AbstractMyBatisSqlGenerator {

    /**
     * select * from t_patient where up_time>='2015-01-10 10:00:10' and up_time < '2015-01-10 10:00:20' order by up_time asc limit 2 offset 2
     */
    @Override
    public String getPagedSql(String basicSql, String indexColumnName, int page, int size) {
        String sql = " %s %s %s >=:indexColumnName order by %s asc  limit %d offset %d";
        var connectionKeyword = getConditionKeywordOfSql(basicSql);// where还是and
        return String.format(sql, basicSql, connectionKeyword, indexColumnName, indexColumnName, size, getOffset(page, size));
    }

    @Override
    public String getPagedSql(String basicSql, int page, int size) {
        String sql = " %s limit %d offset %d";

        return String.format(sql, basicSql, size, getOffset(page, size));

    }

    @Override
    public String getCountSql(String basicSql) {
        String sql = "select count(1) from (%s) inner_query";

        return String.format(sql, basicSql);
    }

    @Override
    public String getFetchSql(String basicSql) {
        String sql = "%s limit 1";
        return String.format(sql, basicSql);
    }

}
